# coding: utf-8
from sqlalchemy import DECIMAL, Column, Date, Integer, String
from sqlalchemy.ext.declarative import declarative_base
import datetime
from sqlalchemy import create_engine, exists, select, func

Base = declarative_base()

class ShippingInfo(Base):
    __tablename__ = 'shipping_info'  # 表名根据你的实际情况修改

    id = Column(Integer, primary_key=True, index=True)
    origin_code = Column(String, index=True)
    destination_code = Column(String, index=True)
    depart_date = Column(Date)
    # arrive_date = Column(Date)
    transport_contractor = Column(String)
    haulage_time = Column(Integer)
    ship_name = Column(String)
    voyage_number = Column(String)

class WebsiteShipping(Base):
    __tablename__ = "t_website_shipping_data"
    __table_args__ = {"comment": "运输路线表"}

    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
    type = Column(
        Integer, nullable=False, default=0, comment="货运类型： 0 海运； 1 空运"
    )
    origin_code = Column(
        String(32), nullable=False, comment="起运地编码，取值来自对应数据表"
    )
    destination_code = Column(
        String(32), nullable=False, comment="目的地编码，取值来自对应数据表"
    )
    depart_date = Column(
        Date, nullable=False, comment="出发日期/下一次出发日期，精确到天"
    )
    arrive_date = Column(Date, nullable=False, comment="到达日期，精确到天")
    haulage_time = Column(
        Integer,
        nullable=False,
        default=1,
        comment="运输时间，单位（海运方式：天； 空运方式：小时）",
    )
    transport_contractor = Column(String(64), comment="承运人，取值来自对应数据表")
    ship_name = Column(String(64), comment="船舶名称，海运方式时有效")
    voyage_number = Column(String(64), comment="航次编号或航班号")
    freight = Column(DECIMAL(10, 2), comment="运费")
    container_type = Column(String(32), comment="货柜类型")
    container_qty = Column(
        Integer, comment="货柜数量，相当于库存，使用一个就要减少一个"
    )
    transfer_code = Column(String(32), comment="中转港编码")
    shipping_lanes = Column(String(32), comment="航线编号")
    update_time = Column(String(32), comment="更新时间")
    def _asdict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
